home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1YP3YK2 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  3.5 KB  |  90 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.JComponent;
  4. import com.sun.java.swing.JInternalFrame;
  5. import com.sun.java.swing.LookAndFeel;
  6. import com.sun.java.swing.border.Border;
  7. import com.sun.java.swing.border.EmptyBorder;
  8. import com.sun.java.swing.plaf.ComponentUI;
  9. import com.sun.java.swing.plaf.UIResource;
  10. import com.sun.java.swing.plaf.basic.BasicInternalFrameUI;
  11. import java.awt.Container;
  12. import java.beans.PropertyChangeListener;
  13.  
  14. public class MetalInternalFrameUI extends BasicInternalFrameUI {
  15.    private MetalInternalFrameTitlePane titlePane;
  16.    private PropertyChangeListener paletteListener;
  17.    private PropertyChangeListener contentPaneListener;
  18.    private static final Border handyEmptyBorder = new EmptyBorder(0, 0, 0, 0);
  19.    protected static String IS_PALETTE = "JInternalFrame.isPalette";
  20.  
  21.    public MetalInternalFrameUI(JInternalFrame b) {
  22.       super(b);
  23.    }
  24.  
  25.    protected JComponent createNorthPane(JInternalFrame w) {
  26.       this.titlePane = new MetalInternalFrameTitlePane(w);
  27.       return this.titlePane;
  28.    }
  29.  
  30.    public static ComponentUI createUI(JComponent c) {
  31.       return new MetalInternalFrameUI((JInternalFrame)c);
  32.    }
  33.  
  34.    public void installUI(JComponent c) {
  35.       super.frame = (JInternalFrame)c;
  36.       this.paletteListener = new PaletteListener(this);
  37.       this.contentPaneListener = new ContentPaneListener(this);
  38.       c.addPropertyChangeListener(this.paletteListener);
  39.       c.addPropertyChangeListener(this.contentPaneListener);
  40.       super.installUI(c);
  41.       Object paletteProp = c.getClientProperty(IS_PALETTE);
  42.       if (paletteProp != null) {
  43.          this.setPalette((Boolean)paletteProp);
  44.       }
  45.  
  46.       Container content = super.frame.getContentPane();
  47.       this.stripContentBorder(content);
  48.       c.setOpaque(false);
  49.    }
  50.  
  51.    public void setPalette(boolean isPalette) {
  52.       if (isPalette) {
  53.          LookAndFeel.installBorder(super.frame, "InternalFrame.paletteBorder");
  54.       } else {
  55.          LookAndFeel.installBorder(super.frame, "InternalFrame.border");
  56.       }
  57.  
  58.       this.titlePane.setPalette(isPalette);
  59.    }
  60.  
  61.    private void stripContentBorder(Object c) {
  62.       if (c instanceof JComponent) {
  63.          JComponent contentComp = (JComponent)c;
  64.          Border contentBorder = contentComp.getBorder();
  65.          if (contentBorder == null || contentBorder instanceof UIResource) {
  66.             contentComp.setBorder(handyEmptyBorder);
  67.          }
  68.       }
  69.  
  70.    }
  71.  
  72.    public void uninstallUI(JComponent c) {
  73.       c.removePropertyChangeListener(this.paletteListener);
  74.       c.removePropertyChangeListener(this.contentPaneListener);
  75.       Container cont = ((JInternalFrame)c).getContentPane();
  76.       if (cont instanceof JComponent) {
  77.          JComponent content = (JComponent)cont;
  78.          if (content.getBorder() == handyEmptyBorder) {
  79.             content.setBorder((Border)null);
  80.          }
  81.       }
  82.  
  83.       super.uninstallUI(c);
  84.    }
  85.  
  86.    static void access$stripContentBorder(MetalInternalFrameUI var0, Object var1) {
  87.       var0.stripContentBorder(var1);
  88.    }
  89. }
  90.